﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>微街秀 >广告图片</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <link href="css/base.css" rel="stylesheet" type="text/css" />
    <link href="plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="plugins/bootstrap-fileinput-master/css/fileinput.min.css" rel="stylesheet"
        type="text/css" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link href="css/EditAdvertisting.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="myform">
    <div class="wamtop">
        <div class="topleft" onclick="window.location.href='Advertisting.html'">
            <img src="img/14.png" />
        </div>
        <div class="topcententxt">
            文章图片</div>
        <div class="topright" style="color: white;">
            确认
        </div>
    </div>
    <div class="Centen">
        <div>
            <div class="divtext">
                <img src="img/22.png" class="iocimg" />
                <input type="text" placeholder="图片的标题" class="advertname" />
            </div>
            <div class="pt10">
                <img id="upimgs" src="img/default-ad.jpg" />
            </div>
            <div class="divtext">
                <img src="img/18.png" class="iocimg" />
                <input type="text" placeholder="图片链接地址" class="advertadress" />
            </div>
        </div>
        <div class="advertloca">
            <div class="location">
                选择广告位置</div>
        </div>
        <div class="Bottomfloat">
            <ul>
                <li>
                    <div class="radius seletag" id="1">
                        顶部</div>
                </li>
                <li style="position: relative;">
                    <div class="radius" style="position: absolute; left: 50%; margin: 0 0 0 -25px;" id="3">
                        悬浮
                    </div>
                </li>
                <li>
                    <div class="radius" style="float: right;" id="2">
                        底部</div>
                </li>
            </ul>
        </div>
        <input type="hidden" id="hftypeid" value="1" />
    </div>
    <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="js/jquery-form.js" type="text/javascript"></script>
    <script src="plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="plugins/bootstrap-fileinput-master/js/fileinput.min.js" type="text/javascript"></script>
    <script src="plugins/bootstrap-fileinput-master/js/fileinput_locale_zh.js" type="text/javascript"></script>
    <script src="js/jquery-submit.js" type="text/javascript"></script>
    <script src="js/dialog.js" type="text/javascript"></script>
    <script src="js/ajax-upload.js" type="text/javascript"></script>
    <script src="js/ajax-data.js" type="text/javascript"></script>
        <script src="js/base.js" type="text/javascript"></script>
        <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
        <script src="js/sha.js" type="text/javascript"></script>
        <script src="js/sign.js" type="text/javascript"></script>
    <script type="text/javascript">
        var Advertid = getUrlArgStr("Advertid");
        var access_token = "";
        $(function () {
            onload(Advertid);
            var param = {};
            AjaxStart("ajax/WxJsApiAccessToken.ashx?get", param, function (data) {
                if (data.code == 0) {
                    var s = sign(data.item.JsApi_Ticket, location.href.split('#')[0]);
                    access_token = data.item.Access_Token;
                    wx.config({
                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。    
                        appId: data.item.AppId, // 必填，公众号的唯一标识    
                        timestamp: s.timestamp, // 必填，生成签名的时间戳    
                        nonceStr: s.nonceStr, // 必填，生成签名的随机串    
                        signature: s.signature,// 必填，签名，见附录1    
                        jsApiList: ['chooseImage', 'uploadImage']
                    });
                }
                else
                    Alert(data.msg);
            });
           

            $(".topright").bind("click", function () {
                if ($(".advertname").val() == "") {
                    toast.show("请输入广告标题");
                    return;
                }
                var lent = $(".advertname").val();

                if (lent.replace(/[^x00-xff]/g, "01").length > 50) {
                    toast.show("输入标题长度超过限制");
                    return;
                }

                if ($("#upimgs").attr("src") == "") {
                    toast.show("请输入广告图片");
                    return;
                }
                if ($(".advertadress").val() == "") {
                    toast.show("请输入广告链接");
                    return;
                }
                var url = $(".advertadress").val();
                if (url.toLowerCase().indexOf("http") == -1)
                    url = "http://" + $(".advertadress").val();
                url = encodeURIComponent(url);

                var paren = "title=" + $(".advertname").val() + "&img=" + $("#upimgs").attr("src") + "&url=" + url + "&type=" + $("#hftypeid").val();

                if (Advertid == "add") {
                    ajax.Addadvert(paren, function (date) {
                        if (date.msg.toString() == "成功") {
                            toast.show("上传成功");
                            window.location.href = "Advertisting.html";
                        }
                    });
                }
                else {
                    ajax.Editadvert(paren + "&id=" + Advertid, function (date) {
                        if (date.msg.toString() == "成功") {
                            toast.show("修改成功");
                            window.location.href = "Advertisting.html";
                        }
                    });
                }


            });
            $(".radius").bind("click", function () {
                $(".radius").removeClass("seletag");
                $(this).addClass("seletag");
                $("#hftypeid").val($(this).attr("id"));
            });
        });
        wx.ready(function () {
            $("#upimgs").click(function () {
                wx.chooseImage({
                    count: 1, // 默认9
                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                    success: function (res) {
                        console.log(res);
                        var imgId = res.localIds[0]; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                        wx.uploadImage({
                            localId: imgId, // 需要上传的图片的本地ID，由chooseImage接口获得
                            isShowProgressTips: 1, // 默认为1，显示进度提示
                            success: function (res) {
                                var serverId = res.serverId; // 返回图片的服务器端ID
                                var url =
                                    "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + access_token + "&media_id=" + serverId;
                                var upapi = "/Client2/Ajax/Upload.ashx?WxImg&is_cut=1&width=640&height=182&url=" + encodeURIComponent(url);
                                console.log(upapi);                                wait.show();                                //上传图片
                                $("#myform").ajaxSubmit({
                                    type: 'post',
                                    dataType: "json",
                                    url: upapi,
                                    success: function (data) {
                                        console.log(data);
                                        wait.dismiss();
                                        $("#upimgs").attr("src", data.item);
                                       
                                    },
                                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                                        wait.dismiss();
                                    }
                                });

                            }
                        });
                    }
                });
            });

        });
        function onload(advertid) {
            if (advertid == "add") return false;
            ajax.Detailadvert("id=" + advertid, function (date) {

                if (date.msg.toString() == "成功") {
                    $(".advertname").val(date.item.title);
                    var url = decodeURIComponent(date.item.url);
                    $(".advertadress").val(url);
                    $("#upimgs").attr("src", date.item.img);
                    $(".upad").css("display", "none");
                    $(".radius").removeClass("seletag");
                    $("#" + date.item.type).addClass("seletag");
                    $("#hftypeid").val(date.item.type);
                }
            });
        }

        //重新显示图片
        function resetImage(src) {
            $("#upimgs").attr("src", src);
        }
    
    </script>
    </form>
</body>
</html>
